<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active{
            background-color: red;
        }
    </style>
</head>
<body>
    
<div id="app">
    <ul>
        <li   v-on:click="changeRed(index)" v-bind:class="getClasses(index)" v-for="(movie, index) in movies">
            {{index}}-{{movie}}-active:{{isActive[index]}}
            {{movies}}
        </li>
    </ul>
</div>

<script src="../js/vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            massage: '你好',
            movies: ['钢铁侠', '蜘蛛侠', '雷神', '美国队长', '复仇者联盟'],
            isActive: [true,false,false,false,false]
        },
        methods: {
            changeRed: function(index){
                //this.isActive[index] = true;
                //通过下标改变数组值时不触发动态刷新，故要用以下方法
 
                Vue.set(this.isActive, index, true)
                //console.log(this.isActive[index]);
                //console.log(this.isActive);
            },
            getClasses: function(index){
                //console.log(index);
                return {active: this.isActive[index]}
            }
        },
    })
</script>
</body>
</html>